//
//  COCOAFANFormatter.m
//  CocoaFan
//
//  Created by Chen Xianan on 3/4/09.
//  Copyright 2009 realazy.org All rights reserved.
//

#import "COCOAFANFormatter.h"


@implementation COCOAFANFormatter
- (NSString *)stringForObjectValue:(id)anObject
{
	anObject = (NSString *)anObject;
	if ([anObject length] > 140)
		return [anObject substringToIndex:139];
	
	return anObject;
}

- (NSAttributedString *)attributedStringForObjectValue:(id)anObject
								 withDefaultAttributes:(NSDictionary *)attributes
{
	anObject = (NSString *)anObject;
	return [[[NSAttributedString alloc] initWithString:anObject
										   attributes:attributes] autorelease];
}

- (BOOL)getObjectValue:(id *)anObject
			 forString:(NSString *)string
	  errorDescription:(NSString **)error
{
	BOOL ret = YES;
	if ([string length] > 140) ret = NO;
	if (anObject) *anObject = string;
	
	return ret;
}

- (BOOL)isPartialStringValid:(NSString *)partialString
			newEditingString:(NSString **)newString
			errorDescription:(NSString **)error
{
	if ([partialString length] > 140) return NO;
	return YES;
}

@end
